/**
 * Copyright © 2016-2025 The Thingsboard Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.terracloud.server.common.data.log;

import com.terracloud.server.common.data.BaseData;
import com.terracloud.server.common.data.id.TenantId;
import com.terracloud.server.common.data.id.PlatformLogId;
import com.terracloud.server.common.data.id.UserId;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 平台日志实体类
 * 用于记录平台自身产生的日志信息
 */
@Schema
@Data
@EqualsAndHashCode(callSuper = true)
public class PlatformLog extends BaseData<PlatformLogId> {

    @Schema(description = "租户ID")
    private TenantId tenantId;
    
    @Schema(description = "用户ID")
    private UserId userId;
    
    @Schema(description = "操作用户")
    private String userName;
    
    @Schema(description = "日志类型")
    private LogType logType;
    
    @Schema(description = "日志级别")
    private LogLevel logLevel;
    
    @Schema(description = "业务ID")
    private String businessId;
    
    @Schema(description = "操作内容")
    private String operationContent;
    
    @Schema(description = "操作详情")
    private String operationDetails;
    
    @Schema(description = "操作参数")
    private String operationParams;
    
    @Schema(description = "状态流转记录")
    private String statusTransition;
    
    @Schema(description = "异常信息")
    private String exceptionInfo;
    
    @Schema(description = "发生时间")
    private Long occurTime;
    
    @Schema(description = "IP地址")
    private String ipAddress;
    
    @Schema(description = "状态")
    private String status;
    
    public PlatformLog() {
        super();
    }
    
    public PlatformLog(PlatformLogId id) {
        super(id);
    }
    
    /**
     * 判断操作是否成功
     * @return true-成功，false-失败
     */
    public boolean isSuccessful() {
        return "成功".equals(status) || "SUCCESS".equals(status);
    }
    
    /**
     * 判断是否为敏感操作
     * @return true-是敏感操作，false-不是敏感操作
     */
    public boolean isSensitiveOperation() {
        // 权限变更相关操作视为敏感操作
        return operationContent != null && 
               (operationContent.contains("权限") || operationContent.contains("授权") || operationContent.contains("权限变更"));
    }
}